From ba0d6cfc6b6cdf9e58ab5c625452ab9c4852764b Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 21 Oct 2009 09:21:01 +0100 Subject: [PATCH] xmalloc_tlsf: Fall back to xmalloc_whole_pages() if xmem_pool_alloc() fails. This was happening for xmalloc request sizes between 3921 and 3951 bytes. The reason being that xmem_pool_alloc() may add extra padding to the requested size, making the total block size greater than a page. Rather than add yet more smarts about TLSF to _xmalloc(), we just dumbly attempt any request smaller than a page via xmem_pool_alloc() first, then fall back on xmalloc_whole_pages() if this fails. Based on bug diagnosis and initial patch by John Byrne Signed-off-by: Keir Fraser --- xen/common/xmalloc_tlsf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index 3f85389e23..6be78e1b98 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -553,7 +553,7 @@ static void tlsf_init(void) void *_xmalloc(unsigned long size, unsigned long align) { - void *p; + void *p = NULL; u32 pad; ASSERT(!in_irq()); @@ -566,10 +566,10 @@ void *_xmalloc(unsigned long size, unsigned long align) if ( !xenpool ) tlsf_init(); - if ( size >= (PAGE_SIZE - (2*BHDR_OVERHEAD)) ) - p = xmalloc_whole_pages(size); - else + if ( size < PAGE_SIZE ) p = xmem_pool_alloc(size, xenpool); + if ( p == NULL ) + p = xmalloc_whole_pages(size); /* Add alignment padding. */ if ( (pad = -(long)p & (align - 1)) != 0 ) @@ -603,7 +603,7 @@ void xfree(void *p) ASSERT(!(b->size & 1)); } - if ( b->size >= (PAGE_SIZE - (2*BHDR_OVERHEAD)) ) + if ( b->size >= PAGE_SIZE ) free_xenheap_pages((void *)b, get_order_from_bytes(b->size)); else xmem_pool_free(p, xenpool); -- 2.30.2